import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const types = {
    SET_AUTH: 'SET_AUTH',
    SET_USER: 'SET_USER'
}

const state = {
  count: 1,
  is_auth: false,
  user: {}
}

const getters = {
  is_auth: state => state.is_auth,
  user: state => state.user
}

const mutations = {
  [types.SET_AUTH] (state, is_auth) {
    if(is_auth) state.is_auth = is_auth
    else state.is_auth = false
  },
  [types.SET_USER] (state, user) {
    state.user = user
  }
}

const actions = {
  setAuth: (({ commit }, is_auth) => {
    commit(types.SET_AUTH, is_auth)
  }),
  setUser: (({commit}, user) => {
    commit(types.SET_USER, user)
  })
}

export default new Vuex.Store({
  state,
  getters,
  mutations,
  actions
})
